package com.hwh.daoIm;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.hwh.dao.StoresDao;
import com.hwh.vo.Stores;

import JDBCUtil.UTIL;

public class StoresDaoImp implements StoresDao{
	
	public ArrayList<Stores> getStores() {

		ArrayList<Stores> stores = new ArrayList<Stores>();
		PreparedStatement pst = null;
		Connection con = UTIL.getConn();

		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("select * from stores");
		try {
			pst = con.prepareStatement(sql.toString());
			// 返回一个结果集
			rs = pst.executeQuery();
			while (rs.next()) {
				// 店铺对象接收结果集的结果
				Stores sto = new Stores();
				sto.setSto_id(rs.getInt("sto_id"));
				sto.setSto_name(rs.getString("sto_name"));
				sto.setSto_blurb(rs.getString("sto_blurb"));
				sto.setSto_address(rs.getString("sto_address"));
				sto.setEstate(rs.getInt("estate"));
				sto.setSell_id(rs.getInt("sell_id"));
				
				stores.add(sto);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				UTIL.closeConn(rs, pst, con);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return stores;
	}
	
}
